from config import APT_PACKAGES
from util import run, ensure_root, file_exists, log, file_backup, file_delete, ln


def install_apt():
    run('sudo apt update')
    run(f'sudo apt install -y {" ".join(APT_PACKAGES)}')

def setup_git():
    run('git config --global url."https://hub.fastgit.org/".insteadOf "https://github.com/"')
    run('git config protocol.https.allow always')

def install_oh_my_zsh():
    if file_exists('~/.oh-my-zsh'):
        log('>>> oh-my-zsh 已安装, 跳过...')
    else:
        run('sh -c "$(curl -fsSL https://raw.fastgit.org/ohmyzsh/ohmyzsh/master/tools/install.sh)"')

def setup_oh_my_zsh():
    path = '~/.zshrc'
    file_backup(path)
    file_delete(path)

    # asdf
    run('git clone https://github.com/asdf-vm/asdf.git ~/.asdf')
    # z
    run('git clone https://github.com/agkozak/zsh-z ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-z')
    # git open
    run('git clone https://github.com/paulirish/git-open.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/git-open')
    # zsh-syntax-highlighting
    run('git clone https://github.com/zsh-users/zsh-syntax-highlighting.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-syntax-highlighting')
    # zsh-autosuggestions
    run('git clone https://github.com/zsh-users/zsh-autosuggestions ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-autosuggestions')
    
    ln('~/my_dot_configs/.zshrc', '~/')

def main():
    install_apt()
    setup_git()
    install_oh_my_zsh()
    setup_oh_my_zsh()

if __name__ == "__main__":
    main()
